package com.siwei.mes.entity.experiment.concrete.batch;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 抗折强度
 *
 * @Description: 抗折强度  CONCRETE_PARAM_KZQD
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2023/12/21 22:29
 */
@Data
public class ConcreteKzqd {
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "单项结论")
    private String dxjl = "";
    @ApiModelProperty(value = "试件尺寸")
    private String sjcc = "";
    @ApiModelProperty(value = "折算系数")
    private String zsxs = "";
    @ApiModelProperty(value = "折算标准强度")
    private String zsbzqd = "";
    @ApiModelProperty(value = "平均值")
    private String pjz = "";
    @ApiModelProperty(value = "到达设计强度")
    private String ddsjqd = "";
    @ApiModelProperty(value = "龄期")
    private String lq = "";
    @ApiModelProperty(value = "到达设计强度")
    private List<KzInfo> kz28d =this.generateQdInfo(3);;

    @Data
    @Accessors(chain = true)
    @ApiModel("强度信息")
    public static class KzInfo {
        @ApiModelProperty(value = "下标")
        private String index = "";
        @ApiModelProperty(value = "破坏荷载")
        private String phhz;
        @ApiModelProperty(value = "抗折强度")
        private String kzqd;
        @ApiModelProperty(value = "压前情况")
        private String yqqk;
        @ApiModelProperty(value = "压后情况")
        private String yhqk;
        @ApiModelProperty(value = "状态")
        private String zt;
        @ApiModelProperty(value = "宽")
        private String kz;
        @ApiModelProperty(value = "高")
        private String gz;
        @ApiModelProperty(value = "支距")
        private String zj;
    }

    /**
     * 生成固定的强度
     *
     * @param i 生成个数
     * @return
     */
    private List<KzInfo> generateQdInfo(int i) {
        List<KzInfo> list = new ArrayList<>();
        for (int j = 0; j < i; j++) {
            int index = i + 1;
            KzInfo kzInfo = new KzInfo().setIndex(index + "").setPhhz("").setKzqd("").setYqqk("").setYhqk("").setZt("");
            list.add(kzInfo);
        }
        return list;
    }


    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    public static JSONObject toJsonObject(Object object) {
        ConcreteKzqd entity = new ConcreteKzqd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteKzqd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteKzqd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    /**
     * 校验必检的
     *
     * @param objJson
     * @return
     */
    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteKzqd entity = JsonUtils.getObject(objJson, ConcreteKzqd.class);
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }
}
